<?php
include_once 'model/page/process.php';
include_once 'model/user/user_create.php';
$board_page = new pages();
$user = new users();
$fillByName = $user->FillOneByName($_SESSION);
$result = $board_page->FillAllDrafts();
$numberTrash = $board_page->FillAllTrash();
$level_decode = json_decode($fillByName["level"], true);
?>
<div id="content">
    <h2 class="jquery_tab_title"><?php echo $phrase["manager_page"] ?></h2>
    <?php if ($level_decode["admin"] != "" || $level_decode["create"] != "") { ?>
        <span class="bglink"><a class="link" href="<?= $url["home"] ?>/menu/pagecreate/t/2"><?php echo $phrase["page_create"] ?></a></span>
        <span class="bglinkleft"><a class="link" href="<?= $url["home"] ?>/menu/page/t/2"><?php echo $phrase["show_pages"] ?></a></span>
        <?php if(mysql_num_rows($numberTrash) > 0) : ?>
            <span class="bglinkleft"><a class="link" href="<?= $url["home"] ?>/menu/pagetrash/t/2"><?php echo $phrase["trash"] ?></a></span>
        <?php endif; ?>
    <?php } ?>
    <table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
        <thead>
            <tr>
                <th width="35%"><?php echo $phrase["page_title"] ?></th>
                <th width="15%"><?php echo $phrase["page_tacgia"] ?></th>
                <th width="35%"><?php echo $phrase["page_summary"] ?></th>
                <th width="15%"><?php echo $phrase["page_date"] ?></th>
                <td class="status" width="8%"></td>
            </tr>
        </thead>
        <tbody>
            <?php
            while ($rows = mysql_fetch_array($result)) {
                $date = new DateTime($rows["page_date"]);
                ?>
                <tr class="gradeC">
                    <td><?php echo $rows["page_title"] ?></td>
                    <td><?php echo $rows["user_fullname"] ?></td>
                    <td><?php echo $rows["page_summary"] ?></td>
                    <td><?php echo $date->format('d/m/Y') ?></td>
                    <?php if ($i % 2) { ?>
                        <td class="first">
                            <?php if ($level_decode["admin"] != "" || $level_decode["update"] != "") { ?>
                                <a href="<?= $url["home"] ?>/menu/pagedelete/t/2/restore/<?php echo $rows["page_id"] ?>">
                                    <image src="<?= $url["home"] ?>/images/icons/upload.png"/>
                                </a>
                                |
                                <a href="<?= $url["home"] ?>/menu/pageupdate/t/2/id/<?php echo $rows["page_id"] ?>">
                                    <image src="<?= $url["home"] ?>/images/icons/edit-icon.gif"/>
                                </a>
                            <?php } ?>
                            <?php if ($level_decode["admin"] != "" || $level_decode["update"] != "" && $level_decode["delete"]) { ?>
                                | 
                            <?php } ?>
                            <?php if ($level_decode["admin"] != "" || $level_decode["delete"] != "") { ?>
                                <a href="<?= $url["home"] ?>/menu/pagedelete/t/2/id/<?php echo $rows["page_id"] ?>" onclick="return confirm('Bạn có chắc chắn muốn xóa không.');">
                                    <image src="<?= $url["home"] ?>/images/icons/b_drop.png"/>
                                </a>
                            <?php } ?>
                        </td>
                    <?php } else { ?>
                        <td class="last">
                            <?php if ($level_decode["admin"] != "" || $level_decode["update"] != "") { ?>
                                <a href="<?= $url["home"] ?>/menu/pagedelete/t/2/restore/<?php echo $rows["page_id"] ?>">
                                    <image src="<?= $url["home"] ?>/images/icons/upload.png"/>
                                </a>
                                |
                                <a href="<?= $url["home"] ?>/menu/pageupdate/t/2/id/<?php echo $rows["page_id"] ?>">
                                    <image src="<?= $url["home"] ?>/images/icons/edit-icon.gif"/>
                                </a>
                            <?php } ?>
                            <?php if ($level_decode["admin"] != "" || $level_decode["update"] != "" && $level_decode["delete"]) { ?>
                                | 
                            <?php } ?> 
                            <?php if ($level_decode["admin"] != "" || $level_decode["delete"] != "") { ?>
                                <a href="<?= $url["home"] ?>/menu/pagedelete/t/2/id/<?php echo $rows["page_id"] ?>" onclick="return confirm('Bạn có chắc chắn muốn xóa không.');">
                                    <image src="<?= $url["home"] ?>/images/icons/b_drop.png"/>
                                </a>
                            <?php } ?>
                        </td>
                    <?php } ?>
                </tr>
            <?php } ?>
        </tbody>
        <tfoot>
            <tr>
                <th colspan="5"></th>
            </tr>
        </tfoot>
    </table>
</div>
<script type="text/javascript">
    $(document).ready(function() {
        $('#example').dataTable({
            "sPaginationType": "full_numbers"
        });
    });
</script>